调用指定分类(包含子分类)下所有产品的评论信息,使用了ecshop系统自带的函数get_children($cat_id)调用指定分类下所有子分类的id,该自带函数在文件include/lib_common.php文件内:
/** * 获得指定分类下的商品评论 * sun04zh3-20130321 * @access public * @param integer $cat_id * @return array */function get_comments_cat_id($cat_id){ $sql = 'SELECT c.id_value, c.user_name, c.content, c.add_time, p.goods_name, p.goods_thumb,p.goods_id FROM '. $GLOBALS['ecs']->table('comment') .' AS c '. ' LEFT JOIN '.$GLOBALS['ecs']->table('goods').' AS p ON p.goods_id = c.id_value '. ' WHERE c.comment_rank = 5 AND c.status = 1 AND c.id_value in (SELECT g.goods_id FROM '. $GLOBALS['ecs']->table('goods').'AS g '.'WHERE '.get_children($cat_id).') ORDER BY c.comment_id DESC LIMIT 5'; $res = $GLOBALS['db']->getAll($sql); $comment = array(); foreach ($res AS $row) { $comment[] = array( 'id_value' => $row['id_value'], 'user_name' => $row['user_name'], 'short_content' => sub_str($row['content'],60), 'content' => $row['content'], 'add_time' => date("Y-m-d H:i:s", $row['add_time']), 'goods_thumb' => $row['goods_thumb'], 'goods_short_name' => sub_str($row['goods_name'],30), 'goods_name' => $row['goods_name'], 'url' => build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']),); } return $comment;}
category.php文件调用:
$smarty->assign('comment', get_comments_cat_id($cat_id));
category.dwt文件显示: